using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.WorkItemTracking;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Controls;
using C1.Win.C1FlexGrid;

namespace Hemi
{
    public class WorkItemMoveInfoList : List<WorkItemMoveInfo>
    {
    }

    public class WorkItemMoveInfo
    {
        WorkItem _workItem = null;
        WorkItem _copy = null;
        Project _destProject = null;
        WorkItemType _destWIT = null;
        ArrayList _missingFields = null;

        public WorkItemMoveInfo(WorkItem workItem, Project targetProject)
        {
            _workItem = workItem;
            _destProject = targetProject;

            if (_destProject.WorkItemTypes.Contains(_workItem.Type.Name))
            {
                _destWIT = _destProject.WorkItemTypes[_workItem.Type.Name];
            }
        }

        public WorkItem WorkItem
        {
            get { return _workItem; }
        }

        public WorkItem Copy
        {
            get { return _copy; }
        }

        public Project DestProject
        {
            get { return _destProject; }
        }

        public WorkItemType DestWIT
        {
            get { return _destWIT; }
            set { _destWIT = value; }
        }

        public ArrayList CreateCopy()
        {
            MessageBox.Show("1" + _destWIT.Project.Name);
           
            //
            // Ah, this probably does not work across team foundation servers
            //
            _copy = _workItem.Copy(_destWIT);
             
            MessageBox.Show("2" + _copy.Project.Name);

            _missingFields = _copy.Validate();

            return _missingFields;
        }

        public ArrayList MissingFields
        {
            get
            {                
                return _missingFields;
            }
            set { _missingFields = value; }
        }

        public bool WITExists
        {
            get
            {
                if (_destWIT != null)
                {
                    return true;
                }
                else
                {
                    return _destProject.WorkItemTypes.Contains(_workItem.Type.Name);
                }
            }
        }
    }
}
